package org.clockworkmages.games.anno1186.generator.sets;

import org.clockworkmages.games.anno1186.DamageConstants;
import org.clockworkmages.games.anno1186.TimeConstants;
import org.clockworkmages.games.anno1186.dao.GameObjectsList;
import org.clockworkmages.games.anno1186.generator.GameObjectGenerator;
import org.clockworkmages.games.anno1186.model.FetishConstants;
import org.clockworkmages.games.anno1186.model.character.GenderConstants;
import org.clockworkmages.games.anno1186.model.character.IncapacitatedState;
import org.clockworkmages.games.anno1186.model.character.NonPlayerCharacter;
import org.clockworkmages.games.anno1186.model.character.SkillConstants;
import org.clockworkmages.games.anno1186.model.character.SpecialAttack;
import org.clockworkmages.games.anno1186.model.character.StatConstants;
import org.clockworkmages.games.anno1186.model.effect.ConditionConstanst;
import org.clockworkmages.games.anno1186.model.option.GenericOption;
import org.clockworkmages.games.anno1186.model.situation.GenericSituation;
import org.clockworkmages.games.anno1186.scripting.tools.EffectBuilder;
import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder;
import org.clockworkmages.games.anno1186.scripting.tools.TextBuilder;

public class PalosFence
		extends GameObjectGenerator
		//
		implements StatConstants, SkillConstants, TechnicalSituationConstants,
		TimeConstants, DamageConstants, ConditionConstanst, GenderConstants {
	public String getFileName() {
		return "palos_fence";
	}

	@Override
	public GameObjectsList generate() {
		GameObjectsList gameObjects = new GameObjectsList();

		GenericOption option = new GenericOption();
		GenericSituation situation = new GenericSituation();

		String PLOT_PALOS_ALLEY_FENCE_ISGONE = "PALOS_ALLEY_FENCE_ISGONE";

		// located options
		option = new GenericOption();
		option.setSituationId("PALOS_ALLEY");
		option.setAddToStack(true);
		option.setSee("a local thug leaning against a wall, watching you from the shadows");
		option.setLabel("Thug");
		option.setIcon("talk");
		option.setGoToCombat("PALOS_THUG");
		option.setCondition("!"
				+ ScriptBuilder.NEW().util().isDay().and().not().plot()
						.is(PLOT_PALOS_ALLEY_FENCE_ISGONE).toString());
		gameObjects.getOptions().add(option);

		NonPlayerCharacter enemy = new NonPlayerCharacter();
		enemy.setId("PALOS_THUG");
		enemy.setName("Criminal");
		enemy.setGender(MALE);
		enemy.setDescription("The local thug...");
		enemy.setLevel(2);
		enemy.getDamageMinimals().put(PHYSICAL, 5d);
		enemy.getDamageRanges().put(PHYSICAL, 10d);
		enemy.getDamageResistances().put(HOLY, -1d);
		enemy.getBaseStats().put(STRENGTH, 20d);
		enemy.getBaseStats().put(ENDURANCE, 20d);
		enemy.getBaseStats().put(AGILITY, 20d);
		enemy.getSpecialAttacks()
				.add(new SpecialAttack(
						"The thug hits you in the stomach with a fist, stunning you for a moment",
						ScriptBuilder
								.NEW()
								.enemy()
								.incapacitate(
										IncapacitatedState.STUNNED.name(), 40)
								.toString(), //
						ScriptBuilder.NEW().util().random(100).le(15)
								.toString()) //
				);
		enemy.setFleeTo("PALOS_MARKET");
		gameObjects.getNpcs().add(enemy);

		// victorious
		// automatically
		option = new GenericOption();
		option.setLabel("Next");
		option.setTextAfter("After the thug breaths his last breath, you loot his corpse and take all valuable items.");
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(30).compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getVictoriousOptions().add(option);

		// Defeated
		option = new GenericOption();
		option.setLabel("Next");
		option.setTextAfter("Having taken some terrible beating you black out completely to wake up several hours later lying in the pool of your blood and robbed of your money. Still, by some dumb luck you're still alive. You probably should be more careful in the future - eventually your luck will run out.");
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(-50).compileEffect());
		option.getEffects()
				.add(EffectBuilder.NEW().me().increaseStat(FATE, -1)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().increaseStat(REPUTATION, -1)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getDefeatedOptions().add(option);

		// Victorious
		option = new GenericOption();
		option.setLabel("Next");
		option.setTextAfter("You loot the bloody corpse of your enemy");
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(30).compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getDefeatedOptions().add(option);

		// Subduing - if none are available, present the
		// VictoriousOption
		enemy.setSubduingText("The thug lies at your feet, defeated. He breaths heavily and seems to have a few ribs broken, but seems otherwise alive. What do you want to do with him?");

		option = new GenericOption();
		option.setLabel("Take all valuable items you can find, but let the poor loser live");
		option.setTextAfter("You search your weakly protesting victim and manage to find some money. Once finished, you walk away and leave the poor loser to live or die, who cares?");
		option.setCondition(ScriptBuilder.NEW().enemy().survived().toString());
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(30).compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduingOptions().add(option);

		option = new GenericOption();
		option.setLabel("Slit his throat and loot the corpse");
		option.setTextAfter("You slit the bastard's throat without as much as blinking and loot the still warm corpse. Once you took the thug's money you walk away.");
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(30).compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().increaseStat(VIRTUE, -2)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduingOptions().add(option);

		option = new GenericOption();
		option.setLabel("Make sure his wounds are not fatal and leave him be.");
		option.setTextAfter("You quickly check the poor loser's life signs to make sure that he'll live. Having found no fatal wounds you leave him be and you walk away - the poor sod learned is lesson already so there's no need to torment him any more.");
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().increaseStat(VIRTUE, 2)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduingOptions().add(option);

		option = new GenericOption();
		option.setCondition(ScriptBuilder
				.NEW()
				.me()
				.isMale()
				.and()
				.util()
				.fetishesEnabled(FetishConstants.MEN,
						FetishConstants.DOMINATION).toString());
		option.setLabel("Rape him.");
		option.setTextAfter("Alone in a dark alley with a handsome stud at your mercy, it would be a waste to not take advantage of the situation. You kick the thug a few times in the ribs and stomach to make sure he won't try to fight back and then you force him to lie face down on the ground as you pull his trousers down and untie your breeches.[TODO]. Once you're satisfied, you grab the thug's purse and walk away.");
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().increaseStat(VIRTUE, -2)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(30).compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().addCondition(SATISFIED, 2, DAY)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduingOptions().add(option);

		// Subdued - if none are available, present the
		// DefeatedOptions

		// complex condition with different scenarios for male and female
		// players:
		String submissionCondition = "("
				+ ScriptBuilder
						.NEW()
						.me()
						.survived()
						.and()
						.me()
						.isMale()
						.and()
						.util()
						.fetishesEnabled(FetishConstants.MEN,
								FetishConstants.SUBMISSION,
								FetishConstants.URINATION, FetishConstants.FEET)
						.toString()
				+ ") || ("
				+ ScriptBuilder
						.NEW()
						.me()
						.survived()
						.and()
						.not()
						.me()
						.isMale()
						.and()
						.util()
						.fetishesEnabled(FetishConstants.MEN,
								FetishConstants.SUBMISSION).toString() + ")";

		enemy.setSubduedText("As you lie on the ground, bruised and defeated, the thug comes closer, a knife in his hand.\n"//
				+ " - Had enough, "
				+ TextBuilder.NEW().iff().me().isMale().then("cocksucker")
						.elsee("bitch").asText()
				+ "? - he says with an evil smile - I should gut you now, and perhaps I yet will. But maybe there's some way you can entertain me instead. How about you hand me over all your money "
				+ TextBuilder
						.NEW()
						.iff()
						.me()
						.isMale()
						.then("and lick my boots clean to prove that you learned to respect your betters, you worthless piece of shit.")
						.elsee(", take off your clothes and get on all fours so I can fuck you like a good little bitch.")
						.asText());

		option = new GenericOption();
		option.setLabel("Try to run away (keep the gold but lose 1 Fate point)");
		option.setTextAfter("You gather all your strength and bolt towards the exit of the alley. Before the thug manages to catch you you turn the corner, and bump right into a pair of city guards on patrol duty. You aplogise for them and as you do, you hear your captor cusing loudly behind you and running away. You were lucky tonight, but you probably should be more careful in the future - eventually your luck will run out.");
		option.setCondition(submissionCondition);
		option.getEffects()
				.add(EffectBuilder.NEW().me().increaseStat(FATE, -1)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduedOptions().add(option);

		option = new GenericOption();
		option.setLabel("Beg for mercy! (Submit)");
		option.setTextAfter(TextBuilder
				.NEW()
				.iff()
				.me()
				.isMale()
				.then("You thank the thug for his mercy and take your eyes off the gleaming blade in the his hand only to kneel at his feet, lowering your lips to lick his boots in complete submission. As you lick the mud of his boots, without raising your head you hear the bandit sheath his knife and untie his trousers. After a moment, you feel a stream of hot liquid hit the back of your head and your back. Though shoucked, you continue to obediently work on your oppressors boots with your tongue. Once the thug's finished pissing, he spits on you, turns away with an amused grunt and walks away.")
				.elsee("Terrified by the perspective of having your throat slit, you do exactly as your oppressor demands.")
				.asText()

		);
		option.setCondition(submissionCondition);
		option.getEffects().add(
				EffectBuilder.NEW().me().increaseStat(REPUTATION, -3)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().plot().set(PLOT_PALOS_ALLEY_FENCE_ISGONE)
						.compileEffect());
		option.getEffects().add(
				EffectBuilder.NEW().me().addGold(-50).compileEffect());
		option.setGoToSituation(ST_EMPTY_RETURN);
		enemy.getSubduedOptions().add(option);

		addDefaultEffectsToCombatOptions(gameObjects);

		return gameObjects;
	}
}
